package org.zzz.mapper;

import org.apache.ibatis.annotations.*;
import org.zzz.entity.Student;
import org.zzz.entity.StudentVo;
import org.zzz.entity.vo.StudentShowVo;

import java.util.List;

/**
 * @Author ZZF
 * @Time 2021/04/20 22:23
 */
public interface StudentMapper {
    /**
     * 添加学生信息
     * @param student
     * @return
     */
    @Insert("insert into student(id,name,gender,class_id) value( #{id} , #{name}, #{gender}, #{classId})")
    int insertStudent(Student student);

    /**
     * 删除学生信息
     * @param id
     * @return
     */
    @Delete("delete from student where id = #{id}")
    int deleteStudentById(@Param("id") String id);

    /**
     * 更新学生信息
     * @param student
     * @return
     */
    @Update("update student set name = #{name}, gender = #{gender}, class_id = #{classId} where id = #{id}")
    int updateStudent(Student student);

    @Select("select * from student where id = #{id}")
    Student getStudentById(@Param("id") String id);

    /**
     * 获取所有学生信息
     * @return
     */
    @Select("select * from student")
    List<Student> listAllStudent();

    @Select("select s.*, c.name as class_name from student s,class c where s.class_id = c.id")
    List<StudentShowVo> listAllStudentShow();

    /**
     * 根据班级id获取学生id集合
     * @param classId
     * @return
     */
    @Select("select id from student where class_id = #{classId}")
    List<String> listStudentIdByClassId(String classId);

    /**
     * 根据学生姓名获取
     * @param name
     * @return
     */
    @Select("select s.*,c.name class_name from student s,class c where s.class_id = c.id and s.name = #{name}")
    StudentShowVo getStudentShowVoByName(@Param("name") String name);

    /**
     * 根据学号获取学生信息
     * @param sid
     * @return
     */
    @Select("select s.*,c.name class_name from student s,class c where s.class_id = c.id and s.id = #{sid}")
    StudentShowVo getStudentShowVoBySid(@Param("sid") String sid);

    /**
     * 根据班级id获取学生
     * @param classId
     * @return
     */
    @Select("select * from student where class_id = #{classId}")
    List<Student> listStudentByClassId(@Param("classId") String classId);
}
